<template>
    <div class="hot_contaienr">
        <w-card-head>
            <div class="title">{{ $t("car.yhjj") }}</div>
        </w-card-head>
        <div class="goods_list" v-if="list.length">
            <el-carousel indicator-position="outside" height="280px" :autoplay="true">
                <el-carousel-item v-for="(item, index) in list" :key="index">
                    <div class="goods_item" v-for="(el, idx) in item">
                        <div class="cover">
                            <img :src="el.imageUrl" v-onerror alt="" srcset="">
                        </div>
                        <div class="goods_detail">
                            <div class="name">{{ el.productName }}</div>
                            <div class="price">HKD{{ el.price }}</div>
                            <div class="add_btn" @click="handleclick(el)">{{ $t("car.jioncar") }}</div>
                        </div>
                    </div>
                </el-carousel-item>
            </el-carousel>
        </div>
        <w-nodata v-if="!list.length"></w-nodata>

        <w-product-pop ref="productPop"></w-product-pop>
        <!-- SKU -->
        <w-taste-pop ref="skuPop"></w-taste-pop>
    </div>
</template>

<script>
import { defineComponent, ref, reactive, nextTick, onMounted, toRaw, toRefs, watch } from 'vue'
import { getAddGoods } from '@/api/mall';
export default defineComponent({
    setup() {
        function splitArray(arr) {
            var result = [];
            for (var i = 0; i < arr.length; i += 2) {
                if (i + 1 >= arr.length) {
                    result.push([arr[i]]);
                }
                else {
                    result.push([arr[i], arr[i + 1]]);
                }
            }
            return result;
        }
        const list = ref([]);
        const init = async (type) => {
            const res = await getAddGoods({ type });
            console.log(splitArray(res), 'xx')
            if (res) {
                list.value = splitArray(res);
            }
        };
        const productPop = ref();
        const skuPop = ref();
        const handleclick = (item) => {
            productPop.value.open(item);
        };
        return {
            productPop,
            skuPop,
            init,
            list,
            handleclick
        };
    },
})
</script>
<style scoped lang='scss'>
.hot_contaienr {
    border: 1px solid red;
    margin: 0 16px;
    border-radius: 5px;
    border: 1px solid rgba(0, 0, 0, 0.12);

    .title {
        padding: 16px 0 12px 16px;
        color: #FFF;
        font-family: "Helvetica Neue";
        font-size: 14px;
        font-style: normal;
        font-weight: 400;
        line-height: normal;
    }

    .goods_list {
        padding: 0 16px;

        .goods_item {
            display: flex;
            flex-direction: row;
            border-bottom: 1px solid rgba(0, 0, 0, 0.08);
            padding-bottom: 16px;
            padding-top: 16px;

            .cover {
                width: 96px;
                height: 96px;
                overflow: hidden;

                img {
                    width: 96px;
                    height: 96px;
                }
            }

            .goods_detail {
                margin-left: 12px;
                width: calc(100% - 108px);

                .name {
                    color: #333;
                    font-family: "Helvetica Neue";
                    font-size: 14px;
                    font-style: normal;
                    word-break: break-all;
                    line-height: 20px;
                    font-weight: 400;
                    display: -webkit-box;
                    -webkit-line-clamp: 2;
                    -webkit-box-orient: vertical;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    /* 142.857% */
                }

                .price {
                    color: #333;
                    font-family: Helvetica;
                    font-size: 16px;
                    font-style: normal;
                    font-weight: 700;
                    line-height: normal;
                    margin-top: 6px;
                }

                .add_btn {
                    color: var(--el-color-primary);
                    border-color: var(--el-color-primary);
                    font-size: 12px;
                    border: 1px solid;
                    text-align: center;
                    border-radius: 5px;
                    padding: 7px 53px;
                    margin-top: 4px;
                }
            }
        }
    }
}
</style>